package com.squirrel.facade;

import com.squirrel.service.CreateUpdateSql;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 对外提供数据更新的方法
 *
 * @author wangyan
 */
public class Update implements SqlOperate {

    private CreateUpdateSql createUpdateSql;
    private DataMedium dataMedium;

    private String tabName;

    public Update() {
        this.dataMedium = new DataMedium();
        this.createUpdateSql = new CreateUpdateSql();
    }

    public CreateUpdateSql getCreateUpdateSql() {
        return this.createUpdateSql;
    }

    public Update setTabName(String tabName) {
        this.tabName = tabName;
        this.dataMedium.setTabName(tabName);
        return this;
    }

    public String getTabName() {
        return this.tabName;
    }

    public Update setUpdateData(DataMedium dataMedium) {
        this.createUpdateSql = new CreateUpdateSql(dataMedium);
        return this;
    }

    public Update setField(String field, Object object) {
        this.dataMedium.setField(field, object);
        this.createUpdateSql.setDataMedium(dataMedium);
        return this;
    }

    public Update setUpdateDatas(List<DataMedium> dataMediums) {
        this.createUpdateSql = new CreateUpdateSql(dataMediums);
        return this;
    }

    public Update where(String field, String condition, String value) {
        createUpdateSql.setWhere(field, condition, value);
        return this;
    }

    public Update where(String field, String condition, LocalDateTime value) {
        createUpdateSql.setWhere(field, condition, value);
        return this;
    }

    public Update where(String field, String condition, Object value) {
        createUpdateSql.setWhere(field, condition, value);
        return this;
    }

    public Update and(String field, String condition, String value) {
        createUpdateSql.setAnd(field, condition, value);
        return this;
    }

    public Update and(String field, String condition, long value) {
        createUpdateSql.setAnd(field, condition, value);
        return this;
    }

    public Update and(String field, String condition, LocalDate value) {
        createUpdateSql.setAnd(field, condition, value);
        return this;
    }

    public Update and(String field, String condition, Object value) {
        createUpdateSql.setAnd(field, condition, value);
        return this;
    }

    public Update and(String field, String condition, LocalDateTime value) {
        createUpdateSql.setAnd(field, condition, value);
        return this;
    }

}
